<?php
/*
 * @Author: your name
 * @Date: 2020-01-03 14:48:40
 * @LastEditTime : 2020-01-03 16:04:54
 * @LastEditors  : Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /ahsmp_3/application/timeexecution/service/Base.php
 */

namespace app\timeexecution\service;

class Base
{
    /**
     * @name: 检查锁
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-03 14:50:54
     */
    public function checkLock ($path, $fileName)
    {
        if (file_exists($path . $fileName))
        {
            $lockTime = file_get_contents($path . $fileName);
            if (time() - $lockTime < 43200)
            {
                echo '程序执行中';
                die;
            }
        }
        
        if (!file_exists($path))
        {
            mkdir($path, 0777, true);
            die;
        }
    }

    /**
     * @name: 写入锁
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-03 14:52:17
     */
    public function wirteLock ($path, $fileName)
    {
        $this->checkLock($path, $fileName);
        file_put_contents($path . $fileName, time());
    }

    /**
     * @name: 删除锁
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-03 14:56:43
     */
    public function delLock ($filePath)
    {
        unlink($filePath);
    }
}
